//    Copyright (C) Kherty.  All rights reserved.
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Reflection;
using OpenLS.Core.Serialization;
using OpenLS.Drawing;

namespace OpenLS.Chart
{
    public class BandFormat : IOfficeXmlSerializable, INotifyPropertyChanged, IShape
    {
        private int index;
        private ShapeProperties spPr;

        public int Index
        {
            get { return index; }
            private set { index = value; notifyPropertyChanged("Index");}
        }

        public ShapeProperties ShapeProperties
        {
            get { return spPr; }
            set { spPr = value; notifyPropertyChanged("ShapeProperties");}
        }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.Read("bandFmt"))
            {
                Index = c.ReadElementIntegerAttribute("idx"); //\\uint?
                ShapeProperties = c.ReadOptionalElement<ShapeProperties>("spPr"); //\\namespace
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("bandFmt"))
            {
                c.WriteElementIntegerAttribute("idx", Index); //\\uint?
                c.WriteOptionalElement(ShapeProperties); //\\namespace
            }
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        void notifyPropertyChanged(string propertyName)
        {
            Contract.Requires(GetType().GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) != null);
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}